package com.leyou.upload.controller;

import com.leyou.upload.service.UploadService;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.net.FileNameMap;
import java.util.Map;
import java.util.UUID;

/**
 * Created with IntelliJ IDEA.
 * User: ycs
 * Date: 2020/8/18
 * Time: 19:47
 * 文件上传控制器
 */
@RestController
public class UploadController {
    @Autowired
    private UploadService uploadService;

    //本地上传
    @PostMapping("/image")
    public ResponseEntity<String> uploadImageToNginx(@RequestParam("file") MultipartFile file) {
        //返回地址值
        String imgUrl = uploadService.uploadImageToNginx(file);
        return ResponseEntity.ok(imgUrl);
    }
    @GetMapping("/signature")
    public ResponseEntity<Map<String,Object>>getOssSignature(){
        //返回签名信息
        Map<String,Object>resultMap=uploadService.getOssSignature();
        return ResponseEntity.ok(resultMap);
    }
}
